package org.codegallery.javagal.concurrent.jcip.c6;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.*;

public class ScheduledExecutorServiceTest {
	public static void main(String[] args) {
		ScheduledExecutorService scheduler = Executors
				.newScheduledThreadPool(1);
		final Runnable beeper = new Runnable() {
			public void run() {
                System.out.println("current beep time:"+new Date().toString());
				System.out.println("beep......");
			}
		};
        System.out.println("start time:"+new Date().toString());
		final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate(
				beeper, 3, 3, SECONDS);
		scheduler.schedule(new Runnable() {
			public void run() {
				System.out.println("current beep cancel time:"+new Date().toString());
				beeperHandle.cancel(true);
			}
		}, 12, SECONDS);
		//System.exit(0);

	}

}
